<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="./vue.js"></script>
    <style>
        html,
        body {
            height: 100%;
            width: 100%;
        }

        .box1 {
            height: 1000px;
            width: 100%;
            border: 1px solid;
            position: relative;
        }

        .box2 {
            height: 100px;
            width: 100px;
            border: solid 1px red;
            position: absolute;
        }
    </style>
</head>

<body>
    <div id="app">
        <div class="box1" @mouseUp="set.bol=false" @mouseMove="set.bol&&move($event)">
            <div class="box2" @mouseDown="click" :style="{left:left+'px',top:top+'px'}">

            </div>
        </div>
    </div>
    <script>
        Vue.config.productionTip = false;
        const vm = new Vue({
            el: "#app",
            data() {
                return {
                    left: 15,
                    top: 15,
                    set: {
                        bol: false,
                        left: '',
                        top: ""
                    }
                };
            },
            methods: {
                click(e) {
                    this.set = {
                        bol: true,
                        left: e.offsetX,
                        top: e.offsetY
                    }
                    console.log(e.offsetX, e.offsetY);
                },
                move(e) {
                    this.left = e.clientX - this.set.left
                    this.top = e.clientY - this.set.top
                    // console.log(e.offsetX, e.clientX);
                }

            },
        });
    </script>
</body>

</html>